package collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * List集合的演示
 */
public class ListDemo {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>(                                                                );
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println(list);

        String s= list.get(2);//获取下标为2的元素
        System.out.println(s);
        for (int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }

        Iterator<String> t=list.iterator();
        while (t.hasNext()){
            System.out.println(t.next());
        }
        for (String i:list){
            System.out.println(i);
        }
        String old=list.set(2,"ssx");//将list中下标为2的元素设置为ssx，同时将原数据返回给old
        System.out.println(old);
        System.out.println(list);


        String aa=list.remove(2);//删除下标为2的元素，并把删除的元素返回给aa
        System.out.println(aa);
        System.out.println(list);

        //void add(int index,E e)
        list.add(2,"three");//在下标为2的位置上插入three
        System.out.println(list);


        List<String> list1 =new ArrayList<>();
        list1.add("aa");
        list1.add("bb");
        list1.add("cc");
        list1.add("dd");
        list1.add("ee");
        System.out.println("list1:"+list1);
        String c=list1.get(3);
        System.out.println(c);

        String q=list1.set(2,"xx");
        System.out.println(q);
        System.out.println(list1);

        String w=list1.remove(2);
        System.out.println(w);
        System.out.println(list1);

         list1.add(2,"cc");
        System.out.println(list1);







    }
}
